import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import*
testCase="DBshop002_余额支付流程"

firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)

firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
firefox.find_element_by_xpath('//input[@type="submit"]').click()
firefox.find_element_by_xpath('//a[@href="/dbshop/goods/8/2"]').click()
switchWindow(firefox,2)
firefox.find_element_by_id('add_cart_submit').click()
time.sleep(1)
firefox.find_element_by_link_text('去购物车结算').click()
firefox.find_element_by_link_text('去结算').click()
firefox.find_element_by_xpath('//input[@value="下一步"]').click()
firefox.find_element_by_xpath('//input[@value="yezf"]').click()
firefox.find_element_by_xpath('//input[@value="确认订单"]').click()
ordernumber = firefox.find_element_by_xpath('(//font[@color="color:#ED145B"])[2]').text
firefox.find_element_by_xpath('//input[@value="马上去支付"]').click()

firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,'销售管理','订单管理')
firefox.find_element_by_name('order_sn').send_keys(ordernumber)
firefox.find_element_by_xpath('//button').click()
firefox.find_element_by_link_text('编辑查看').click()
firefox.find_element_by_link_text('发货操作').click()
firefox.find_element_by_xpath('//button').click()

firefox.get(url)
firefox.find_element_by_link_text('我的订单').click()
firefox.find_element_by_partial_link_text('已发货').click()
firefox.find_element_by_name('search_order_sn').send_keys(ordernumber)
firefox.find_element_by_xpath('//button').click()
firefox.find_element_by_xpath('//button[text()="确认收货"]').click()
firefox.find_element_by_xpath('//button[@type="submit"]').click()
firefox.switch_to.alert.accept()
firefox.find_element_by_name('search_order_sn').send_keys(ordernumber)
firefox.find_element_by_xpath('//button').click()

try:
    firefox.find_element_by_link_text(ordernumber).is_displayed()
    writeLog("%s 测试通过"%testCase)
    print("%s 测试通过" % testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
    print("%s 测试失败" % testCase)
firefox.quit()